import { createApp } from 'vue'
// import './style.css'
import App from './App.vue'
import router from './router'
import api from './api'

router.beforeEach((to, from) => {
  const token = localStorage.getItem('h5_token')
  // 非登录页面，token不存在
  if (!token && to.path !== '/login') {
    return '/login'
  } else if (token && to.path === '/login') {
    return '/'
  } else {
    return true
  }
})

const app = createApp(App)

// 在实例上绑定属性
app.config.globalProperties.$api = api

// 路由挂载
app.use(router)

app.mount('#app')
